package kksoft.kkexpress.funcs;

import kksoft.kkexpress.executor.ExecuteException;

public class SwitchFunc {

    public Object run(Object which, Object... caseAndValues) throws ExecuteException {
        if (caseAndValues.length == 0) {
            return null;
        }
        if (caseAndValues.length % 2 != 0) {
            throw new ExecuteException("switch case and values not peers: " + caseAndValues.toString());
        }
        for (int i = 0; i < caseAndValues.length; i += 2) {
            if (which.equals(caseAndValues[i])) {
                return caseAndValues[i + 1];
            }
        }
        return null;
    }

}
